/**
 * jims
 */
package com.jims.master.modules.template.service;

import com.jims.master.common.persistence.Page;
import com.jims.master.common.service.CrudService;
import com.jims.master.modules.sys.utils.UserUtils;
import com.jims.master.modules.template.dao.TreatProjectItemDao;
import com.jims.master.modules.template.entity.TreatProjectItem;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Service
 * @author 系统管理员
 * @version 2017-06-02
 */
@Service
@Transactional(readOnly = true)
public class TreatProjectItemService extends CrudService<TreatProjectItemDao, TreatProjectItem> {

	public TreatProjectItem get(String id) {
		return super.get(id);
	}
	
	public List<TreatProjectItem> findList(TreatProjectItem treatProjectItem) {
		return super.findList(treatProjectItem);
	}
	
	public Page<TreatProjectItem> findPage(Page<TreatProjectItem> page, TreatProjectItem treatProjectItem) {
		return super.findPage(page, treatProjectItem);
	}
	
	@Transactional(readOnly = false)
	public int save(TreatProjectItem treatProjectItem) {
		UserUtils userUtils = new UserUtils();
		return super.save(treatProjectItem);
	}
	
	@Transactional(readOnly = false)
	public int delete(TreatProjectItem treatProjectItem) {
		return super.delete(treatProjectItem);
	}


	@Transactional(readOnly = false)
	public int saveChina(TreatProjectItem treatProjectItem) {
		int num = 0;
		List<TreatProjectItem> list = treatProjectItem.getTreatItemList();
		for (TreatProjectItem item:list){
			if("".equals(item.getId()) ||  item.getId() == null){
				item.setApplyId(treatProjectItem.getApplyId());
				item.setAdministration(treatProjectItem.getAdministration());
				item.setPerformFreq(treatProjectItem.getPerformFreq());
				item.setRepetition(treatProjectItem.getRepetition());
				item.preInsert();
				item.updateOrgId();
				num = dao.insert(item);
			} else {
				item.updateOrgId();
				dao.update(item);
			}

		}
		return num;
	}
}